﻿@model PieListViewModel

@ViewBag.CurrentCategory
@foreach (var pie in Model.Pies)
{
    @Html.Partial("PieOverviewSummary", pie)
}


@*use api controller to get data, here is just a demo
<div id="pieDiv"></div>

@section Scripts{

    <script>

        $(function() {
            LoadMorePies();
        });

        // 滑倒屏幕低端再次发送请求
        $(window).scroll(function() {
            if ($(window).scrollTop() + 1 >= $(document).height() - $(window).height()) {
                LoadMorePies();
            }
        });

        function LoadMorePies() {

            $.ajax({
                type: 'GET',
                url: '/api/PieData',
                dataType: 'json',
                success: function(jsonData) {
                    if (jsonData == null) {
                        alert('no data returned');
                        return;
                    }

                    $.each(jsonData,
                        function(index, pie) {

                            var pieSummarString = `<div class="col-sm-4 col-lg-4 col-md-4">
                                                        <div class="thumbnail">
                                                            <img src="${pie.imageThumbnailUrl}" alt="">
                                                            <div class="caption">
                                                                <h3 class="pull-right">${pie.price}</h3>
                                                                <h3><a href="/Pie/Details/${pie.pieId}">${pie.name
                                }</a></h3>
                                                                <p>${pie.shortDescription}</p>
                                                            </div>
                                                            <div class="addToCart">
                                                                <p class="button">
                                                                    <a class="btn btn-primary" href="/ShoppingCart/AddToShoppingCart?pieId=${
                                pie.pieId}">Add to cart</a>
                                                                </p>
                                                            </div>
                                                        </div>
                                                    </div>`;

                            $('#pieDiv').append(pieSummarString);
                        });
                },
                error: function(ex) {
                    alert(ex);
                }
            });
            return false;
        }
    </script>

}
*@